﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Kalman.Extensions;
using Kalman;
using Microsoft.AspNetCore.Mvc;
using NLog.Web.LayoutRenderers;
using Microsoft.AspNetCore.Authorization;

namespace QuDao.Api.Controllers
{
    /// <summary>
    /// 销售汇总API
    /// </summary>
    [AllowAnonymous]
    public class SalesSummaryController : ApiControllerBase
    {
        /// <summary>
        /// 获取代理首页销售统计数据（日订单统计，月订单统计）
        /// </summary>
        /// <param name="agentID">代理ID</param>
        /// <param name="date">销售日期</param>
        [HttpGet]
        public SalesStatOfHomeDto GetSummaryOfHome(long agentID, DateTime date)
        {
            var day = SalesDailyBO.Instance.GetItem(agentID, date);
            var month = SalesDailyBO.Instance.GetSummaryByMonth(agentID, date);

            var orderNum = day == null ? 0 : day.OrderNum;
            var amount = day == null ? 0 : day.Amount;
            return new SalesStatOfHomeDto { OrderNumOfDay = orderNum, OrderAmountOfDay = amount, OrderNumOfMonth = month.Item1, OrderAmountOfMonth = month.Item2 };
        }

        /// <summary>
        /// 获取团队业绩汇总数据列表（按天统计）
        /// </summary>
        /// <param name="tid">租户ID</param>
        /// <param name="agentID">代理ID</param>
        /// <param name="beginDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns></returns>
        [HttpGet]
        public List<SummaryOfDailyDto> GetSummaryListOfDaily([FromHeader] int tid, long agentID, DateTime beginDate, DateTime endDate)
        {
            return SalesDailyBO.Instance.GetSummaryListOfDaily(tid, agentID, beginDate, endDate);
        }

        /// <summary>
        /// 获取团队业绩汇总数据列表（按月统计）
        /// </summary>
        /// <param name="tid">租户ID</param>
        /// <param name="agentID">代理ID</param>
        /// <param name="beginDate">开始日期（可以传开始月份的任意一天）</param>
        /// <param name="endDate">结束日期（可以传结束月份的任意一天）</param>
        /// <returns></returns>
        [HttpGet]
        public List<SummaryOfMonthDto> GetSummaryListOfMonth([FromHeader] int tid, long agentID, DateTime beginDate, DateTime endDate)
        {
            return SalesDailyBO.Instance.GetSummaryListOfMonth(tid, agentID, beginDate, endDate);
        }

    }
}
